package com;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;


public class Sjlx3 {
    public static void main(String[] args) throws IOException {
        showPhoneInfo();
    }
    public static void showPhoneInfo() throws IOException {
        Document doc=null;
        try {
            SAXReader saxReader=new SAXReader();
            doc= (Document) saxReader.read(new File("src/com/手机信息.xml"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        Element root=doc.getRootElement();

        Element brand=root.element("Brand");
        Element xm=brand.addElement("XM");
        xm.setText("小米");

        OutputFormat format=OutputFormat.createPrettyPrint();
        format.setEncoding("UTF-8");
        XMLWriter write=new XMLWriter(new FileWriter("src/com/手机信息.xml"),format);
        write.write(doc);
        write.close();
    }
}
